package com.dw.etl.core.service;

import com.dw.etl.common.util.SnowflakeIdWorker;
import  com.dw.etl.common.vo.PaginationVO;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.EtlRemindService;
import com.dw.etl.core.mapper.EtlRemindMapper;
import com.dw.etl.core.bean.model.EtlRemind;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * etlRemind服务实现类
 * Created by hozeData on 2021/06/16.
 */
@Service
@Transactional
public class EtlRemindServiceImpl implements EtlRemindService{

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlRemindServiceImpl.class);

    @Autowired
    private EtlRemindMapper etlRemindMapper;

    @Override
    public int insert(EtlRemind etlRemind) {
        if(etlRemind==null){
            Long uuid32 = SnowflakeIdWorker.getId();
            etlRemind.setId(uuid32);
        }
        return etlRemindMapper.insert(etlRemind);
    }

    @Override
    public int insertSelective(EtlRemind etlRemind)  {
        if(etlRemind==null){
            Long uuid32 = SnowflakeIdWorker.getId();
            etlRemind.setId(uuid32);
        }
        return etlRemindMapper.insertSelective(etlRemind);
    }

    @Override
    public int deleteById(Long id)  {
        return etlRemindMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByIdSelective(EtlRemind etlRemind)  {

        return etlRemindMapper.updateByPrimaryKeySelective(etlRemind);
    }

    @Override
    public int updateById(EtlRemind etlRemind)  {
        return etlRemindMapper.updateByPrimaryKey(etlRemind);
    }

    @Override
    public EtlRemind getById(Long id)  {
        return etlRemindMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<EtlRemind> findByModel(EtlRemind etlRemind)  {
        return etlRemindMapper.findByModel(etlRemind);
    }

    @Override
    public PaginationVO<EtlRemind> findPageByModel(EtlRemind etlRemind, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlRemind> quesList = etlRemindMapper.findByModel(etlRemind);
        PageInfo<EtlRemind> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlRemind> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public int insert(String des, Byte level,String cont) {
        EtlRemind remind = new EtlRemind();
        remind.setDes(des);
        remind.setDtCre(new Date());
        remind.setLev(level);
        remind.setCont(cont);
        int a = this.insert(remind);
        return a;
    }
}
